/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jul.giftmanager.ui.view;

import com.alee.extended.panel.WebCollapsiblePane;
import com.alee.laf.scroll.WebScrollPane;
import com.jul.giftmanager.obj.Person;
import com.jul.giftmanager.ui.AddPersonInfoPanel;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

/**
 *
 * @author user
 */
public class ViewFriendsPanel extends JPanel
{
    private WebCollapsiblePane friendsContainer;
    private WebScrollPane container;

    public ViewFriendsPanel()
    {
        friendsContainer = new WebCollapsiblePane();
        container = new WebScrollPane(friendsContainer);
        init();
    }
    
    private void init(){
        setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
        container.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
        container.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        add(container);
    }
    
    public void setFriendsList(List<Person> friends){
            AddPersonInfoPanel infoPanel = new AddPersonInfoPanel();
            infoPanel.setPersonToAdd(friends.get(0));
            friendsContainer.add(new WebCollapsiblePane("0", convertPersonObjectListToUIComponents(friends).get(0)) );
            friendsContainer.add(new WebCollapsiblePane("0", convertPersonObjectListToUIComponents(friends).get(0)) );
            friendsContainer.add(new WebCollapsiblePane("0", convertPersonObjectListToUIComponents(friends).get(0)) );
            friendsContainer.add(new WebCollapsiblePane("0", convertPersonObjectListToUIComponents(friends).get(0)) );
            friendsContainer.add(new WebCollapsiblePane("0", convertPersonObjectListToUIComponents(friends).get(0)) );
    }
    
    private List<JComponent> convertPersonObjectListToUIComponents(List<Person> friends){
        List<JComponent> components = new ArrayList<JComponent>(friends.size());
        
        for (Person person : friends)
        {
            AddPersonInfoPanel infoPanel = new AddPersonInfoPanel();
            infoPanel.setPersonToAdd(person);
            components.add(infoPanel);
            infoPanel = null;
        }
        return components;
    }
}
